<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ page import="java.util.*"%>
<%@ page import="com.qqtop10.manager.model.temp.*"%>
<!DOCTYPE html>
<html lang="zh">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>运营管理平台 - 顶十</title>
<%@include file="../include/imports.jsp"%>
<script src="/assets/js/manager/systeminfo.js"></script>
<script src="/assets/js/select2-master/dist/js/select2.full.min.js"></script>
<link href="/assets/js/select2-master/dist/css/select2.min.css"
	rel="stylesheet">
<script src="/assets/js/manager/buildIndexPage.js" type="text/javascript"></script>
<style>
.input-box {
	display: block;
	margin-left: 50px;
}

.input-box .form-control {
	width: 380px;
}

.goods {
	width: 380px;
}

.category {
	width: 200px;
}
</style>
</head>
<body style="overflow: auto;">

	<%
		List<BuildIndexCategoryTemp> category = (List<BuildIndexCategoryTemp>) request.getAttribute("category");
		List<BuildIndexGoodsTemp> goods = (List<BuildIndexGoodsTemp>) request.getAttribute("goods");
		
		List<FloorTempData> floorData = (List<FloorTempData>) request.getAttribute("floorData");
	%>

	<%!public String getCategoryData(List<BuildIndexCategoryTemp> list) {
		StringBuffer categoryBuf = new StringBuffer();
		categoryBuf.append("<option value=\"0\">请选择分类</option>");
		for (int i = 0; i < list.size(); i++) {
			if(list.get(i).getUuid().length() == 32){
				categoryBuf.append("<option value=\"" + list.get(i).getUuid() + "\">" + list.get(i).getName() + "</option>");
			}
		}
		return categoryBuf.toString();
	}%>

	<%!public String getGoodsData(List<BuildIndexGoodsTemp> list) {
		StringBuffer goodsBuf = new StringBuffer();
		goodsBuf.append("<option value=\"0\">请选择商品</option>");
		for (int i = 0; i < list.size(); i++) {
			if(list.get(i).getUuid().length() == 32){
				goodsBuf.append("<option value=\"" + list.get(i).getUuid() + "\">" + list.get(i).getName() + "</option>");
			}
		}
		return goodsBuf.toString();
	}%>

	<div class="navbar" role="navigation">
		<%@include file="../include/top.jsp"%>
	</div>

	<div class="container-fluid content">
		<div class="row">
			<%@include file="../include/menu.jsp"%>
			<div class="main">
				<div class="row">
					<div class="col-lg-12">
						<ol class="breadcrumb">
							<li><i class="fa fa-home"></i><a href="index.do">首页</a></li>
							<li><i class="fa fa-laptop"></i><span>生成首页</span></li>
						</ol>
					</div>
				</div>
				<div class="row toolbox">
					<input type="button" id="addFloor" class="btn btn-sm btn-primary" value="增加楼层" /> 
					<input type="button" id="deleteLastFloor" class="btn btn-sm btn-danger" value="删除最后一楼" style="width: 100px;" />
					<input type="button" id="buildIndex" class="btn btn-sm btn-primary" value="生成首页" />
				</div>

				<form action="#" method="post" id="floor">
				
				
				<%  if(floorData != null){  
						for(int k = 0; k < floorData.size(); k++){
							FloorTempData flData = floorData.get(k);
							//处理每一楼已选择的分类
							String[] categoryUuids = flData.getCategoryUuids();
							String[] categoryText = flData.getCategoryText();
// 							Set<String> categoryKeys = categoryMap.keySet();
// 							Iterator<String> iter = categoryKeys.iterator();
							List<String> cuList = Arrays.asList(categoryUuids);
							List<String> ctList = Arrays.asList(categoryText);
// 							while(iter.hasNext()){
// 								cList.add(iter.next());
// 							}
							
							//处理每一楼已选择的商品
							String[] goodsUuids = flData.getGoodsUuids();
							String[] goodsText = flData.getGoodsText();
							
							List<String> guList = Arrays.asList(goodsUuids);
							List<String> gtList = Arrays.asList(goodsText);
// 							Map<String, String> goodsMap = flData.getGoods();
// 							Set<String> goodsKeys = goodsMap.keySet();
// 							Iterator<String> gIter = goodsKeys.iterator();
// 							List<String> gList = new ArrayList<String>();
// 							while(gIter.hasNext()){
// 								gList.add(gIter.next());
// 							}
							
				%>
						<div class="floors">
						<div class="showFloorsNum">
							<span style='color: red; font-size: 18px;'><%=flData.getFloorId()%>楼</span>
						</div>
						<input type="hidden" value="<%=flData.getFloorId()%>" readonly class="floorIndex"
							name="floor">
						<div class="categoryDiv">
							<label>推荐分类</label>
							<div class="cDiv">
								<span>分类1</span> 
								<select class="category" name="categoryUuid">
									<option value="<%=cuList.get(0) %>"><%=ctList.get(0) %></option>
									<%=getCategoryData(category) %>
								</select> 
								
								<span>分类2</span> 
								<select class="category" name="categoryUuid">
								<option value="<%=cuList.get(1) %>"><%=ctList.get(1) %></option>
									<%=getCategoryData(category) %>
								</select> 
								
								<span>分类3</span> 
								<select class="category" name="categoryUuid">
								<option value="<%=cuList.get(2) %>"><%=ctList.get(2) %></option>
									<%=getCategoryData(category) %>
								</select> 
								
								<span>分类4</span> 
								<select class="category" name="categoryUuid">
								<option value="<%=cuList.get(3) %>"><%=ctList.get(3) %></option>
									<%=getCategoryData(category) %>									
								</select> 
								
								<span>分类5</span> 
								<select class="category" name="categoryUuid">
								<option value="<%=cuList.get(4) %>"><%=ctList.get(4) %></option>
									<%=getCategoryData(category) %>
								</select> 
								
								<br> 
								
								<span>分类6</span> 
								<select class="category" name="categoryUuid">
								<option value="<%=cuList.get(5) %>"><%=ctList.get(5) %></option>
									<%=getCategoryData(category) %>
								</select> 
								
								<span>分类7</span> 
								<select class="category" name="categoryUuid">
								<option value="<%=cuList.get(6) %>"><%=ctList.get(6) %></option>
									<%=getCategoryData(category) %>
								</select> 
								
								<span>分类8</span> 
								<select class="category" name="categoryUuid">
								<option value="<%=cuList.get(7) %>"><%=ctList.get(7) %></option>
									<%=getCategoryData(category) %>
								</select> 
								
								<span>分类9</span> 
								<select class="category" name="categoryUuid">
								<option value="<%=cuList.get(8) %>"><%=ctList.get(8) %></option>
									<%=getCategoryData(category) %>
								</select> 
								
								<span>分类10</span> 
								<select class="category" name="categoryUuid">
								<option value="<%=cuList.get(9) %>"><%=ctList.get(9) %></option>
									<%=getCategoryData(category) %>
								</select>
							</div>
						</div>
						<div class="goodsDiv">
							<label>推荐商品</label>
							<div class="gDiv">
								
								<span>推荐商品1：</span>
								<select class="goods" name="goodsUuid">
									<option value="<%=guList.get(0) %>"><%=gtList.get(0) %></option>
									<%=getGoodsData(goods) %>
								</select> 
								<br>
								
								<span>推荐商品2：</span>
								<select class="goods" name="goodsUuid">
									<option value="<%=guList.get(1) %>"><%=gtList.get(1) %></option>
									<%=getGoodsData(goods) %>
								</select> 
								<br>
								
								<span>推荐商品3：</span>
								<select class="goods" name="goodsUuid">
									<option value="<%=guList.get(2) %>"><%=gtList.get(2) %></option>
									<%=getGoodsData(goods) %>
								</select> 
								<br>
								
								<span>推荐商品4：</span>
								<select class="goods" name="goodsUuid">
									<option value="<%=guList.get(3) %>"><%=gtList.get(3) %></option>
									<%=getGoodsData(goods) %>
								</select> 
								<br>
								
								<span>推荐商品5：</span>
								<select class="goods" name="goodsUuid">
									<option value="<%=guList.get(4) %>"><%=gtList.get(4) %></option>
									<%=getGoodsData(goods) %>
								</select> 
								<br>
								
								<span>推荐商品6：</span>
								<select class="goods" name="goodsUuid">
									<option value="<%=guList.get(5) %>"><%=gtList.get(5) %></option>
									<%=getGoodsData(goods) %>
								</select> 
								<br>
								
								<span>推荐商品7：</span>
								<select class="goods" name="goodsUuid">
									<option value="<%=guList.get(6) %>"><%=gtList.get(6) %></option>
									<%=getGoodsData(goods) %>
								</select> 
								<br>
								
								<span>推荐商品8：</span>
								<select class="goods" name="goodsUuid">
									<option value="<%=guList.get(7) %>"><%=gtList.get(7) %></option>
									<%=getGoodsData(goods) %>
								</select> 
								<br>
								
								<span>推荐商品9：</span>
								<select class="goods" name="goodsUuid">
									<option value="<%=guList.get(8) %>"><%=gtList.get(8) %></option>
									<%=getGoodsData(goods) %>
								</select>
								
								<br>
								<span>推荐商品10：</span>
								<select class="goods" name="goodsUuid">
									<option value="<%=guList.get(9) %>"><%=gtList.get(9) %></option>
									<%=getGoodsData(goods) %>
								</select>
								
							</div>
						</div>
					
					
					</div>
					<hr />
						<%
						}
					}else{
				%>
					<div class="floors">
						<div class="showFloorsNum">
							<span style='color: red; font-size: 18px;'>1楼</span>
						</div>
						<input type="hidden" value="1" readonly class="floorIndex"
							name="floor">
						<div class="categoryDiv">
							<label>推荐分类</label>
							<div class="cDiv">
								<span>分类1</span> 
								<select class="category" name="categoryUuid">
									<%=getCategoryData(category) %>
								</select> 
								
								<span>分类2</span> 
								<select class="category" name="categoryUuid">
									<%=getCategoryData(category) %>
								</select> 
								
								<span>分类3</span> 
								<select class="category" name="categoryUuid">
									<%=getCategoryData(category) %>
								</select> 
								
								<span>分类4</span> 
								<select class="category" name="categoryUuid">
									<%=getCategoryData(category) %>									
								</select> 
								
								<span>分类5</span> 
								<select class="category" name="categoryUuid">
									<%=getCategoryData(category) %>
								</select> 
								
								<br> 
								
								<span>分类6</span> 
								<select class="category" name="categoryUuid">
									<%=getCategoryData(category) %>
								</select> 
								
								<span>分类7</span> 
								<select class="category" name="categoryUuid">
									<%=getCategoryData(category) %>
								</select> 
								
								<span>分类8</span> 
								<select class="category" name="categoryUuid">
									<%=getCategoryData(category) %>
								</select> 
								
								<span>分类9</span> 
								<select class="category" name="categoryUuid">
									<%=getCategoryData(category) %>
								</select> 
								
								<span>分类10</span> 
								<select class="category" name="categoryUuid">
									<%=getCategoryData(category) %>
								</select>
							</div>
						</div>
						<div class="goodsDiv">
							<label>推荐商品</label>
							<div class="gDiv">
								
								<span>推荐商品1：</span>
								<select class="goods" name="goodsUuid">
									<%=getGoodsData(goods) %>
								</select> 
								<br>
								
								<span>推荐商品2：</span>
								<select class="goods" name="goodsUuid">
									<%=getGoodsData(goods) %>
								</select> 
								<br>
								
								<span>推荐商品3：</span>
								<select class="goods" name="goodsUuid">
									<%=getGoodsData(goods) %>
								</select> 
								<br>
								
								<span>推荐商品4：</span>
								<select class="goods" name="goodsUuid">
									<%=getGoodsData(goods) %>
								</select> 
								<br>
								
								<span>推荐商品5：</span>
								<select class="goods" name="goodsUuid">
									<%=getGoodsData(goods) %>
								</select> 
								<br>
								
								<span>推荐商品6：</span>
								<select class="goods" name="goodsUuid">
									<%=getGoodsData(goods) %>
								</select> 
								<br>
								
								<span>推荐商品7：</span>
								<select class="goods" name="goodsUuid">
									<%=getGoodsData(goods) %>
								</select> 
								<br>
								
								<span>推荐商品8：</span>
								<select class="goods" name="goodsUuid">
									<%=getGoodsData(goods) %>
								</select> 
								<br>
								
								<span>推荐商品9：</span>
								<select class="goods" name="goodsUuid">
									<%=getGoodsData(goods) %>
								</select>
								<br>
								<span>推荐商品10：</span>
								<select class="goods" name="goodsUuid">
									<%=getGoodsData(goods) %>
								</select>
							</div>
						</div>
					</div>
					<hr />
					<%} %>
				</form>
			</div>
		</div>
	</div>
	<%@include file="../include/modal.jsp"%>
	<div class="clearfix"></div>
	
	<script type="text/javascript">
		$(function(){
			$("#addFloor").click(function(){
				var index = Number($(".floorIndex").last().val());
				index += 1;
				var floorTemplate = 
					'<div class="floors">'+
						'<div class="showFloorsNum">'+
						'	<span style="color: red; font-size: 18px;">' + index + '楼</span>'+
						'</div>'+
						'<input type="hidden" value="' + index + '" readonly class="floorIndex"'+
						'	name="floor">'+
						'<div class="categoryDiv">'+
						'	<label>推荐分类</label>'+
						'	<div class="cDiv">'+
						'		<span>分类1</span>'+ 
						'		<select class="category" name="categoryUuid">'+
						'			<%=getCategoryData(category) %>'+
						'		</select> '+
						'		<span>分类2</span>'+ 
						'		<select class="category" name="categoryUuid">'+
						'			<%=getCategoryData(category) %>'+
						'		</select> '+
						'		<span>分类3</span>'+ 
						'		<select class="category" name="categoryUuid">'+
						'			<%=getCategoryData(category) %>'+
						'		</select> '+
						'		<span>分类4</span>'+ 
						'		<select class="category" name="categoryUuid">'+
						'			<%=getCategoryData(category) %>			'+						
						'		</select> '+
						'		<span>分类5</span>'+ 
						'		<select class="category" name="categoryUuid">'+
						'			<%=getCategoryData(category) %>'+
						'		</select> '+
						'		'+
						'		<br>'+ 
						'		<span>分类6</span>'+ 
						'		<select class="category" name="categoryUuid">'+
						'			<%=getCategoryData(category) %>'+
						'		</select> '+
						'		<span>分类7</span>'+ 
						'		<select class="category" name="categoryUuid">'+
						'			<%=getCategoryData(category) %>'+
						'		</select> '+
						'		<span>分类8</span>'+ 
						'		<select class="category" name="categoryUuid">'+
						'			<%=getCategoryData(category) %>'+
						'		</select> '+
						'		<span>分类9</span>'+ 
						'		<select class="category" name="categoryUuid">'+
						'			<%=getCategoryData(category) %>'+
						'		</select> '+
						'		<span>分类10</span>'+ 
						'		<select class="category" name="categoryUuid">'+
						'			<%=getCategoryData(category) %>'+
						'		</select>'+
						'	</div>'+
						'</div>'+
						'<div class="goodsDiv">'+
						'<label>推荐商品</label>'+
						'<div class="gDiv">'+
						'	<span>推荐商品1：</span>'+
						'	<select class="goods" name="goodsUuid">'+
						'		<%=getGoodsData(goods) %>'+
						'	</select>'+ 
						'	<br>'+
						'	<span>推荐商品2：</span>'+
						'	<select class="goods" name="goodsUuid">'+
						'		<%=getGoodsData(goods) %>'+
						'	</select> '+
						'	<br>'+
						'	<span>推荐商品3：</span>'+
						'	<select class="goods" name="goodsUuid">'+
						'		<%=getGoodsData(goods) %>'+
						'	</select> '+
						'	<br>'+
						'	<span>推荐商品4：</span>'+
						'	<select class="goods" name="goodsUuid">'+
						'		<%=getGoodsData(goods) %>'+
						'	</select> '+
						'	<br>'+
						'	<span>推荐商品5：</span>'+
						'	<select class="goods" name="goodsUuid">'+
						'		<%=getGoodsData(goods) %>'+
						'	</select> '+
						'	<br>'+
						'	<span>推荐商品6：</span>'+
						'	<select class="goods" name="goodsUuid">'+
						'		<%=getGoodsData(goods) %>'+
						'	</select> '+
						'	<br>'+
						'	<span>推荐商品7：</span>'+
						'	<select class="goods" name="goodsUuid">'+
						'		<%=getGoodsData(goods) %>'+
						'	</select> '+
						'	<br>'+
						'	<span>推荐商品8：</span>'+
						'	<select class="goods" name="goodsUuid">'+
						'		<%=getGoodsData(goods) %>'+
						'	</select> '+
						'	<br>'+
						'	<span>推荐商品9：</span>'+
						'	<select class="goods" name="goodsUuid">'+
						'		<%=getGoodsData(goods) %>'+
						'	</select>'+
						'	<br>'+
						'	<span>推荐商品10：</span>'+
						'	<select class="goods" name="goodsUuid">'+
						'		<%=getGoodsData(goods) %>'+
						'	</select>'+
						'</div>'+
					'</div>'+
				'</div>'+
				'<hr />';
				$("#floor").append(floorTemplate);
				
				
				  var $disabledResults = $(".floors").eq(index-1).find(".goods"); $disabledResults.select2();
				  
					 var category = $(".floors").eq(index-1).find(".category"); category.select2();
			});
		});
	</script>
</body>
</html>